﻿Imports System.Diagnostics
Public Class frmProcess
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Refreshlstbox()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle Then
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        Else
            Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle
        End If
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        Dim i As Integer = ListBox1.SelectedIndex
        Refreshlstbox()
        lblName.Text = ListBox1.SelectedIndex
        Dim procList() As Process = Process.GetProcesses()
        Dim strProcName As String = procList(i).ProcessName
        Dim iproID As Integer = procList(i).Id
        lblName.Text = "Process name: " & strProcName
        TextBox1.Text = iproID
        TextBox2.Text = procList(i).HandleCount
    End Sub

    Private Sub Refreshlstbox()
        Dim procList() As Process = Process.GetProcesses()
        Dim i As Integer
        ListBox1.Items.Clear()
        For i = 0 To UBound(procList) - 1 Step i + 1
            Dim strProcName As String = procList(i).ProcessName
            Dim iProcID As Integer = procList(i).Id
            ListBox1.Items.Add(procList(i).ProcessName)
        Next
    End Sub

    Private Sub cmdKillChrome_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdKillChrome.Click
        Dim procList() As Process = Process.GetProcessesByName("chrome")
        Dim i As Integer
        For i = 0 To UBound(procList) Step i + 1
            procList(i).Kill()
        Next
    End Sub
End Class
